#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
const int N = 110, M = N * N;
int p[N];
int n, m;
int find(int x)
{
	if (x != p[x]) {
		p[x] = find(p[x]);
	}
	return p[x];
}
struct node
{
	int a, b, w;
}s[M];
int cmp(node a, node b)
{
	return a.w < b.w;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		memset(p, 0, sizeof(p));
		memset(s, 0, sizeof(s));
		vector<int>alls;
		alls.clear();
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			p[i] = i;
		}
		for (int i = 0; i < m; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			s[i] = { a,b,c };
		}
		sort(s, s + m, cmp);
		for (int i = 0; i < m; i++) {
			int a = find(s[i].a);
			int b = find(s[i].b);
			int w = s[i].w;
			if (a != b) {
				p[a] = b;
				ans += w;
				alls.push_back(i);
			}
		}
		bool flag = 1;
		for (auto x : alls) {
			int cnt = 0;
			int sum = 0;
			for (int i = 1; i <= n; i++) {
				p[i] = i;
			}
			for (int i = 0; i < m; i++) {
				if (i == x) {
					continue;
				}
				int a = find(s[i].a);
				int b = find(s[i].b);
				int w = s[i].w;	
				if (a != b) {
					p[a] = b;
					sum += w;
					cnt++;
				}
			}
			if (ans == sum && cnt == n - 1) {
				flag = 0;
			}
		}
		if (flag) {
			cout << ans << endl;
		}
		else {
			cout << "Not Unique!" << endl;
		}
	}
	return 0;
}